home *** CD-ROM | disk | FTP | other *** search
- function CollapseMenu()
- {
- this.createEmptyMovieClip("collapseMenu_mc",5);
- this.parentDepth = 10;
- this.parentSettings = {unpressedcolor:11141120,hoverunpressedcolor:16711680,pressedcolor:52224,hoverpressedcolor:65280};
- this.parentItems = new Array();
- this.childSettings = {unpressedcolor:11141120,hoverunpressedcolor:16711680,pressedcolor:52224,hoverpressedcolor:65280};
- this.mainSettings = {expansionDurationInFrames:6,h:300,w:400};
- this.childItems = new Object();
- this.currHeight = 0;
- this.scrollToCurrChildAfterExpand = false;
- this.child_tf = new TextFormat();
- this.child_labelX = 26;
- this.child_labelY = 0;
- this.child_labelW = 105;
- this.child_labelH = 19;
- this.child_tf.font = "childEmbedFont";
- this.child_tf.size = 11;
- }
- CollapseMenu.prototype = new MovieClip();
- Object.registerClass("CollapseMenuSymbol",CollapseMenu);
- CollapseMenu.prototype.init = function(xmlSetupStr, theChildNodeCallBack)
- {
- var menuXML = new XML(xmlSetupStr);
- if(menuXML.status == 0)
- {
- var cn = menuXML.firstChild;
- while(cn)
- {
- if(cn.nodeName == "mainSettings")
- {
- this.mainSettings.expansionDurationInFrames = cn.attributes.expansionDurationInFrames;
- this.mainSettings.h = cn.attributes.h;
- this.mainSettings.w = cn.attributes.w;
- }
- else if(cn.nodeName == "parentSettings")
- {
- this.parentSettings.unpressedcolor = cn.attributes.unpressedcolor;
- this.parentSettings.hoverunpressedcolor = cn.attributes.hoverunpressedcolor;
- this.parentSettings.pressedcolor = cn.attributes.pressedcolor;
- this.parentSettings.hoverpressedcolor = cn.attributes.hoverpressedcolor;
- }
- else if(cn.nodeName == "childSettings")
- {
- this.childSettings.unpressedcolor = cn.attributes.unpressedcolor;
- this.childSettings.hoverunpressedcolor = cn.attributes.hoverunpressedcolor;
- this.childSettings.pressedcolor = cn.attributes.pressedcolor;
- this.childSettings.hoverpressedcolor = cn.attributes.hoverpressedcolor;
- if(cn.attributes.labelX != null)
- {
- this.child_labelX = cn.attributes.labelX;
- }
- if(cn.attributes.labelY != null)
- {
- this.child_labelY = cn.attributes.labelY;
- }
- if(cn.attributes.labelW != null)
- {
- this.child_labelW = cn.attributes.labelW;
- }
- if(cn.attributes.labelH != null)
- {
- this.child_labelH = cn.attributes.labelH;
- }
- if(cn.attributes.fontsize != null)
- {
- this.child_tf.size = cn.attributes.fontsize;
- }
- }
- else if(cn.nodeName == "parent")
- {
- var cp = this.createParentItem(cn,this.currHeight);
- this.currHeight += cp.childContainer_mc._y + 4;
- }
- cn = cn.nextSibling;
- }
- }
- this.collapseMenu_mc.controller = this;
- this.collapseMenu_mc.getWidth = function()
- {
- return this._width;
- };
- this.collapseMenu_mc.getHeight = function()
- {
- return this.controller.currHeight;
- };
- this.attachMovie("FScrollPaneSymbol","sp_mc",2);
- this.sp_mc.controller = this;
- this.sp_mc.addProperty("contentHeight",this.getCurrHeight,null);
- this.sp_mc.setSize(this.mainSettings.w,this.mainSettings.h);
- this.sp_mc.setScrollContent(this.collapseMenu_mc);
- this.childNodeCallBack = theChildNodeCallBack;
- };
- CollapseMenu.prototype.getCurrHeight = function()
- {
- return this.controller.currHeight;
- };
- CollapseMenu.prototype.createParentItem = function(parentNode, initialY)
- {
- var depth = this.parentDepth + this.parentItems.length;
- this.collapseMenu_mc.attachMovie("ParentItemSymbol","p" + depth,depth);
- this.collapseMenu_mc["p" + depth]._y = initialY;
- this.collapseMenu_mc["p" + depth].controller = this;
- this.parentItems.push(this.collapseMenu_mc["p" + depth]);
- this.collapseMenu_mc["p" + depth].init(parentNode);
- this.collapseMenu_mc["p" + depth].index = this.parentItems.length - 1;
- return this.collapseMenu_mc["p" + depth];
- };
- CollapseMenu.prototype.parentItemClicked = function(parentItem)
- {
- this.ignoreClicks = true;
- this.delta = parentItem.childrenHeight;
- this.dir = !parentItem.isExpanded ? 1 : -1;
- this.currHeight -= this.dir * this.delta;
- this.currFrame = 1;
- this.howLong = parentItem.expansionDurationInFrames == null ? this.mainSettings.expansionDurationInFrames : parentItem.expansionDurationInFrames;
- this.affectedParent = parentItem;
- this.parentStartIndex = parentItem.index + 1;
- this.onEnterFrame = function()
- {
- if(this.currFrame <= this.howLong)
- {
- var i = this.parentStartIndex;
- while(i < this.parentItems.length)
- {
- if(this.currFrame == 1)
- {
- this.parentItems[i].startY = this.parentItems[i]._y;
- }
- var cf = this.currFrame;
- this.parentItems[i]._y = this.dir * this.delta * (cf /= this.howLong) * (cf - 2) + this.parentItems[i].startY;
- i++;
- }
- this.affectedParent.exposeChildren(this.currFrame,this.howLong,this.dir);
- this.currFrame = this.currFrame + 1;
- }
- else
- {
- var i = this.parentStartIndex;
- while(i < this.parentItems.length)
- {
- this.parentItems[i]._y = this.parentItems[i].startY - this.dir * this.delta;
- i++;
- }
- this.ignoreClicks = false;
- this.affectedParent.updateState();
- this.sp_mc.refreshPane();
- this.sp_mc.refreshPane();
- if(this.scrollToCurrChildAfterExpand)
- {
- this.scrollToCurrChildAfterExpand = false;
- this.scrollCurrChildIntoView();
- }
- else
- {
- delete this.onEnterFrame;
- }
- }
- };
- };
- CollapseMenu.prototype.childItemClicked = function(childItem)
- {
- if(this.currChild)
- {
- this.currChild.unClick();
- }
- this.currChild = childItem;
- this.childNodeCallBack(this.currChild);
- };
- CollapseMenu.prototype.selectItem = function(itemName)
- {
- var c = this.childItems[itemName];
- if(c != null)
- {
- if(this.currChild != c)
- {
- this.currChild.unClick();
- this.currChild = c;
- this.currChild.showAsPressed();
- }
- trace(this.currChild.parentItem._target);
- if(this.currChild.parentItem.isExpanded)
- {
- this.scrollCurrChildIntoView();
- }
- else
- {
- this.scrollToCurrChildAfterExpand = true;
- this.currChild.parentItem.doPress();
- }
- }
- return c;
- };
- CollapseMenu.prototype.scrollCurrChildIntoView = function()
- {
- var p = {x:this.currChild._x,y:this.currChild._y};
- this.currChild._parent.localToGlobal(p);
- this.globalToLocal(p);
- var delta = 0;
- if(p.y < this.sp_mc._y)
- {
- delta = this.sp_mc._y - p.y;
- }
- else if(p.y + this.currChild._height > this.sp_mc._y + this.sp_mc._height)
- {
- delta = this.sp_mc._y + this.sp_mc._height - (p.y + 2 * this.currChild._height);
- }
- if(delta != 0)
- {
- this.ignoreClicks = true;
- this.delta = delta;
- this.sp_mc.startY = this.sp_mc.getScrollPosition().y;
- this.currFrame = 1;
- this.howLong = Math.floor(this.delta / 40);
- if(this.howLong < 2)
- {
- this.howLong = 2;
- }
- this.onEnterFrame = function()
- {
- if(this.currFrame <= this.howLong)
- {
- var cf = this.currFrame;
- this.sp_mc.setScrollPosition(0,this.delta * (cf /= this.howLong) * (cf - 2) + this.sp_mc.startY);
- this.currFrame = this.currFrame + 1;
- }
- else
- {
- this.parentItems[i]._y = this.delta + this.collapseMenu_mc.startY;
- this.ignoreClicks = false;
- delete this.onEnterFrame;
- }
- };
- }
- };
-